{% load staticfiles %}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1 , user-scalable=no">
<title>比赛场地添加</title>
<link href="{% static 'plugins/bootstrap.css' %}" rel="stylesheet">
<link href="{% static 'plugins/bootstrap-dashen.css' %}" rel="stylesheet">
<link href="{% static 'plugins/font-awesome.css' %}" rel="stylesheet">
<link href="{% static 'plugins/animate.css' %}" rel="stylesheet">
<link href="{% static 'plugins/bootstrap-datetimepicker.min.css' %}" rel="stylesheet" media="screen">
</head>
<body style="margin-top:70px;">
<div class="container">
{% include 'header.html' %}
	<div class="col-md-12 wow fadeInLeft">
		<ul class="breadcrumb">
  			<li><a href="{% url 'Index:index' %}">首页</a></li>
  			<li><a href="{% url 'ContestPlace:frontList' %}">比赛场地管理</a></li>
  			<li class="active">添加比赛场地</li>
		</ul>
		<div class="row">
			<div class="col-md-10">
		      	<form class="form-horizontal" name="contestPlaceAddForm" id="contestPlaceAddForm" enctype="multipart/form-data" method="post"  class="mar_t15">
				    {% csrf_token %}
				  <div class="form-group">
					 <label for="contestPlace_placeNo" class="col-md-2 text-right">场地编号:</label>
					 <div class="col-md-8"> 
					 	<input type="text" id="contestPlace_placeNo" name="contestPlace.placeNo" class="form-control" placeholder="请输入场地编号">
					 </div>
				  </div> 
				  <div class="form-group">
				  	 <label for="contestPlace_contestItemObj_classId" class="col-md-2 text-right">运动项目:</label>
				  	 <div class="col-md-8">
					    <select id="contestPlace_contestItemObj_classId" name="contestPlace.contestItemObj.classId" class="form-control">
                            {% for contestItem in contestItems %}
                            <option value="{{ contestItem.classId }}">{{ contestItem.className }}</option>
                            {% endfor %}
					    </select>
				  	 </div>
				  </div>
				  <div class="form-group">
				  	 <label for="contestPlace_placeName" class="col-md-2 text-right">场地名称:</label>
				  	 <div class="col-md-8">
					    <input type="text" id="contestPlace_placeName" name="contestPlace.placeName" class="form-control" placeholder="请输入场地名称">
					 </div>
				  </div>
				  <div class="form-group">
				  	 <label for="contestPlace_placeArea" class="col-md-2 text-right">场地面积:</label>
				  	 <div class="col-md-8">
					    <input type="text" id="contestPlace_placeArea" name="contestPlace.placeArea" class="form-control" placeholder="请输入场地面积">
					 </div>
				  </div>
				  <div class="form-group">
				  	 <label for="contestPlace_placePhoto" class="col-md-2 text-right">场地照片:</label>
				  	 <div class="col-md-8">
					    <img  class="img-responsive" id="contestPlace_placePhotoImg" border="0px"/><br/>
							    <input id="contestPlace_placePhoto" name="contestPlace.placePhoto" type="file" size="50" />
				  	 </div>
				  </div>
				  <div class="form-group">
				  	 <label for="contestPlace_useDateDiv" class="col-md-2 text-right">投入使用时间:</label>
				  	 <div class="col-md-8">
		                <div id="contestPlace_useDateDiv" class="input-group date contestPlace_useDate col-md-12" data-link-field="contestPlace_useDate" data-link-format="yyyy-mm-dd">
		                    <input class="form-control" id="contestPlace_useDate" name="contestPlace.useDate" size="16" type="text" value="" placeholder="请选择投入使用时间" readonly>
		                    <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
		                    <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
		                </div>
				  	 </div>
				  </div>
				  <div class="form-group">
				  	 <label for="contestPlace_placeDesc" class="col-md-2 text-right">场地描述:</label>
				  	 <div class="col-md-8">
					    <textarea id="contestPlace_placeDesc" name="contestPlace.placeDesc" rows="8" class="form-control" placeholder="请输入场地描述"></textarea>
					 </div>
				  </div>
		          <div class="form-group">
		             <span class="col-md-2"></span>
		             <span onclick="ajaxContestPlaceAdd();" class="btn btn-primary bottom5 top5">添加</span>
		          </div> 
		          <style>#contestPlaceAddForm .form-group {margin:5px;}  </style>  
				</form> 
			</div>
			<div class="col-md-2"></div> 
	    </div>
	</div>
</div>
{% include 'footer.html' %}
<script src="{% static 'plugins/jquery.min.js' %}"></script>
<script src="{% static 'plugins/bootstrap.js' %}"></script>
<script src="{% static 'plugins/wow.min.js' %}"></script>
<script src="{% static 'plugins/bootstrapvalidator/js/bootstrapValidator.min.js' %}"></script>
<script type="text/javascript" src="{% static 'plugins/bootstrap-datetimepicker.min.js' %}" charset="UTF-8"></script>
<script type="text/javascript" src="{% static 'plugins/locales/bootstrap-datetimepicker.zh-CN.js' %}" charset="UTF-8"></script>
<script>
	//提交添加比赛场地信息
	function ajaxContestPlaceAdd() { 
		//提交之前先验证表单
		$("#contestPlaceAddForm").data('bootstrapValidator').validate();
		if(!$("#contestPlaceAddForm").data('bootstrapValidator').isValid()){
			return;
		}
		jQuery.ajax({
			type : "post",
			url : "{% url 'ContestPlace:frontAdd' %}",
			dataType : "json" , 
			data: new FormData($("#contestPlaceAddForm")[0]),
			success : function(obj) {
				if(obj.success){ 
					alert("保存成功！");
					location.reload();
				} else {
					alert(obj.message);
				}
			},
			processData: false, 
			contentType: false, 
		});
	} 
$(function(){
	/*小屏幕导航点击关闭菜单*/
    $('.navbar-collapse a').click(function(){
        $('.navbar-collapse').collapse('hide');
    });
    new WOW().init();
	//验证比赛场地添加表单字段
	$('#contestPlaceAddForm').bootstrapValidator({
		feedbackIcons: {
			valid: 'glyphicon glyphicon-ok',
			invalid: 'glyphicon glyphicon-remove',
			validating: 'glyphicon glyphicon-refresh'
		},
		fields: {
			"contestPlace.placeNo": {
				validators: {
					notEmpty: {
						message: "场地编号不能为空",
					}
				}
			},
			"contestPlace.placeName": {
				validators: {
					notEmpty: {
						message: "场地名称不能为空",
					}
				}
			},
			"contestPlace.placeArea": {
				validators: {
					notEmpty: {
						message: "场地面积不能为空",
					},
					numeric: {
						message: "场地面积不正确"
					}
				}
			},
			"contestPlace.useDate": {
				validators: {
					notEmpty: {
						message: "投入使用时间不能为空",
					}
				}
			},
		}
	}); 
	//投入使用时间组件
	$('#contestPlace_useDateDiv').datetimepicker({
		language:  'zh-CN',  //显示语言
		format: 'yyyy-mm-dd',
		minView: 2,
		weekStart: 1,
		todayBtn:  1,
		autoclose: 1,
		minuteStep: 1,
		todayHighlight: 1,
		startView: 2,
		forceParse: 0
	}).on('hide',function(e) {
		//下面这行代码解决日期组件改变日期后不验证的问题
		$('#contestPlaceAddForm').data('bootstrapValidator').updateStatus('contestPlace.useDate', 'NOT_VALIDATED',null).validateField('contestPlace.useDate');
	});
})
</script>
</body>
</html>
